import { request } from '@umijs/max';

export interface LoginDataVO {
  token: string;
  userInfo: {
    id: number;
    email: string;
    username: string;
    avatar?: string;
  };
}

export interface LoginParams {
  email: string;
  password?: string;
  code?: string;
  loginType: 'PASSWORD' | 'CODE';
}

export async function login(params: LoginParams) {
  return request<LoginDataVO>('/user/login', {
    method: 'POST',
    data: params,
  });
}

export async function logout() {
  return request('/user/logout', {
    method: 'POST',
  });
}

export async function getUserInfo() {
  return request('/user/info', {
    method: 'GET',
  });
} 